<?php
namespace app\admin\validate;

use think\Validate;

class Article extends Validate
{
    protected $rule = [
        'title'  	=>  'require|checkTitleUnique',
        'content'  	=>  'require',
    ];

    protected $message  =   [
        'title.require' 	=> -10003, 
        'title.unique' 		=> -10009, 
        'content.require' 	=> -10004, 
    ];
    protected $scene = [
        'add'   =>  ['title'],
    ];
    /**
     * 自定义验证规则 文章标题不能重复
     * @param  string $title 文章标题
     * @return bool|int        
     */
    protected function checkTitleUnique($title)
    {
        return true;
        // $res = model('article')->where(array('is_delete' => 1))->where(array('title' => $title))->value('title');
        // if($res == null) {
        //     return true;
        // } else {
        //     return -10009;
        // }
    }

}